#!/bin/bash
# -*- coding: utf-8 -*-
#
#       build_macboot.py
#  
#       Author: weiketing <weikting@gmail.com>
#       

####$1 image filename
####$2 image label
####$3 iso_root

. config.py

imgfile=$1
tmpdir=/tmp/.macboot
tmpimg=${imgfile}.tmp

mkdir -p ${tmpdir}
dd if=/dev/zero of=${tmpimg} bs=2880K count=1 &>/dev/null
mkfs.hfsplus -v ${CD_LABEL} ${tmpimg} &>/dev/null
sudo sh -c "umount ${tmpdir};mount ${tmpimg} ${tmpdir} -o loop,uid=$UID " 2>/dev/null
mkdir -p ${tmpdir}/System/Library/CoreServices/
echo "This file is required for booting" > ${tmpdir}/mach_kernel
sed "s/PRODUCTVERSION/${CD_LABEL}/" SystemVersion.plist.in >${tmpdir}/System/Library/CoreServices/SystemVersion.plist
png2icns ${tmpdir}/.VolumeIcon.icns grubcd_logo.png &>/dev/null
cp -va ${ISO_ROOT}/[eE][fF][iI]/[bB][oO][oO][Tt]/[bB][oO][oO][Tt][xX]64.efi  ${tmpdir}/System/Library/CoreServices/boot.efi
sudo ./hfs-bless ${tmpdir}/System/Library/CoreServices/boot.efi
sync
sudo sh -c "umount ${tmpdir} &>/dev/null"
mv ${tmpimg} ${imgfile}
rm -rf ${tmpdir}
